package com.leenleda.ips.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeUtils {

    /*
     * 将时间戳转换为时间
     */
    public static String stampToDate(long s) {

        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long lt = new Long(s);////时间戳为10位需*1000，时间戳为13位的话不需乘1000
        Date date = new Date(lt);
        res = simpleDateFormat.format(date) + "";
        return res;
    }

    public static String stampToTime(long s) {

        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
        long lt = new Long(s);////时间戳为10位需*1000，时间戳为13位的话不需乘1000
        Date date = new Date(lt);
        res = simpleDateFormat.format(date) + "";
        return res;
    }

    public static long getDaySecond(long time){
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date(time);
        res = simpleDateFormat.format(date) + "";

//        LogUtils.e("SKDVNDSLV", "=====time===" + time);
        LogUtils.e("getDaySecond", "=======res=" + res);
        long timeStart = timeStrToLong(res);

        LogUtils.e("getDaySecond", "=======timeStart=" + timeStart);
        return timeStart;
    }

    public static long timeStrToLong(String str){
        Long timestamp = null;
        try {
            timestamp = new SimpleDateFormat("yyyy-MM-dd").parse(str).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return timestamp;
    }
}
